$(document).ready(function() {		
	//第一次查询，无参数查询
	$.ajax( {
		type : "post",
		url : "work/MyAdvice_findMyAdvice1.action",
		success : showData
	});
	
	/*$("#firstPage").click(function(){
		var total=$("#total").text();
		var page=1;
		var maxRow=$("#maxRow").text();
		var UId=$("#UId").val();
		var UName=$("#UName").val();
		var duId=$("#duId").val();
		var dsName=$("#dsName").val();
		
		var timeStart=$("#timeStart").val();
		var timeEnd=$("#timeEnd").val();
		
		$("#listPerson").empty();
		$("#loadingPerson").fadeIn("slow");
		$.ajax({
  			type: "post",
 			url: "wsq/Sched_find.action",
 			data:{"total":total,"page":page,"maxRow":maxRow,
			      "UId":UId,"duId":duId,"dsName1":dsName,"UName":UName,
			      "timeStart":timeStart,
			      "timeEnd":timeEnd
 				 },
  			success:showData
		});
	});
	
	$("#prePage").click(function(){		
		var total=$("#total").text();
		var page=$("#page").text();
		var maxRow=$("#maxRow").text();
		var UId=$("#UId").val();
		var UName=$("#UName").val();
		var duId=$("#duId").val();
		var dsName=$("#dsName").val();
		
		var timeStart=$("#timeStart").val();
		var timeEnd=$("#timeEnd").val();
		
		page=(parseInt(page)-1);
		$("#listPerson").empty();
		$("#loadingPerson").fadeIn("slow");
		$.ajax({
			type: "post",
 			url: "wsq/Sched_find.action",
 			data:{"total":total,"page":page,"maxRow":maxRow,
			      "UId":UId,"duId":duId,"dsName1":dsName,"UName":UName,
			      "timeStart":timeStart,
			      "timeEnd":timeEnd
 				 },
  			success:showData
		});
	});
	
	$("#nextPage").click(function(){		
		var total=$("#total").text();
		var page=$("#page").text();
		page=(parseInt(page)+1);
		var maxRow=$("#maxRow").text();
		var UId=$("#UId").val();
		var UName=$("#UName").val();
		var duId=$("#duId").val();
		var dsName=$("#dsName").val();
		
		var timeStart=$("#timeStart").val();
		var timeEnd=$("#timeEnd").val();
		
		$("#listPerson").empty();
		$("#loadingPerson").fadeIn("slow");
		$.ajax({
			type: "post",
 			url: "wsq/Sched_find.action",
 			data:{"total":total,"page":page,"maxRow":maxRow,
			      "UId":UId,"duId":duId,"dsName1":dsName,"UName":UName,
			      "timeStart":timeStart,
			      "timeEnd":timeEnd
 				 },
  			success:showData
		});
	});
	
	$("#lastPage").click(function(){
		var total=$("#total").text();
		var page=$("#pageCount").text();
		var maxRow=$("#maxRow").text();
		var UId=$("#UId").val();
		var UName=$("#UName").val();
		var duId=$("#duId").val();
		var dsName=$("#dsName").val();
		
		var timeStart=$("#timeStart").val();
		var timeEnd=$("#timeEnd").val();
		
		$("#listPerson").empty();
		$("#loadingPerson").fadeIn("slow");
		$.ajax({
			type: "post",
 			url: "wsq/Sched_find.action",
 			data:{"total":total,"page":page,"maxRow":maxRow,
			      "UId":UId,"duId":duId,"dsName1":dsName,"UName":UName,
			      "timeStart":timeStart,
			      "timeEnd":timeEnd
 				 },
  			success:showData
		});
	});
	
	$("#jumpPage").click(function(){
		var total=$("#total").text();
		var maxRow=$("#maxRow").text();
		var pageCount=$("#pageCount").text();
		var UId=$("#UId").val();
		var UName=$("#UName").val();
		var UId=$("#UName").val();
		var duId=$("#duId").val();
		var dsName=$("#dsName").val();
		
		var timeStart=$("#timeStart").val();
		var timeEnd=$("#timeEnd").val();		
		var page=$("#jump").val();
		
		if(page>pageCount){
			alert("jumpPage > pageCount");
			return;
		}
		$("#listPerson").empty();
		$("#loadingPerson").fadeIn("fast");
		$.ajax({
			type: "post",
 			url: "wsq/Sched_find.action",
 			data:{"total":total,"page":page,"maxRow":maxRow,
			      "UId":UId,"duId":duId,"dsName1":dsName,"UName":UName,
			      "timeStart":timeStart,
			      "timeEnd":timeEnd
 				 },
  			success:showData
		});
	});*/
	
	function showData(data){
		$("#listPerson").empty();	
		if(data.myAdviceList.length == 0){
			$("#loadingPerson").hide();
			$("#nonePerson").show();
			//$("#total").text(0);
			//$("#page").text(0);
			//$("#pageCount").text(0);
			//$("#maxRow").text(0);
		}else{
			$("#listPerson").hide();
			$("#nonePerson").hide();
		    $("#loadingPerson").hide();
		    $.each(data.myAdviceList,function(i,n){
		    	var c = "申请";
		    	if(n.c=='1001') {c="申请";}
		    	else if(n.c=='1002') {c="已读未回复";}
		    	else if(n.c=='1003') {c="已回复"}
				fillDataToHtml(n.daId, n.tbEvent.EEventname, n.b, n.daContent, n.tbUserByApplyUId.UName, 
						n.daApplyTime, n.daLastestTime, n.daSubmitTime, c);
		  	});
		$("#listPerson").show();
		//$("#total").text(data.pageUtil.total);
		//$("#page").text(data.pageUtil.page);
		//$("#pageCount").text(Math.ceil(data.pageUtil.total/10));
		//$("#maxRow").text(data.pageUtil.maxRow);
		}
	}
	
	function fillDataToHtml(daId,EEventname,b,daContent,UName,daApplyTime,daLastestTime,daSubmitTime,c){
		var strHtml="<tr>";
		strHtml+="<td id='"+daId+"'><span><input name='read' type='radio' /></span></td>";
		strHtml+="<td ><span>"+EEventname+"</span></td>";	
		strHtml+="<td ><span>"+b+"</span></td>";
		strHtml+="<td ><span>"+daContent+"</span></td>";
		strHtml+="<td ><span>"+UName+"</span></td>";
		strHtml+="<td ><span>"+daApplyTime+"</span></td>";
		strHtml+="<td ><span>"+daLastestTime+"</span></td>";
		strHtml+="<td ><span>"+daSubmitTime+"</span></td>";
		strHtml+="<td ><span>"+c+"</span></td>";
        strHtml+="</tr>";
        $("#listPerson").append(strHtml);
        
        var id = "#"+daId;
        $(id).click(function(){
        	
        	$('#mainFrame', window.parent.document).attr("src", "work/MyAdvice_findByDaId1.action?daId="+daId);
        	
        });
	}
});